{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Quantum simulator\n",
        "\n",
        "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.png)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/mindquantum/zh_cn/mindspore_quantum_simulator.ipynb)&emsp;\n",
        "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.png)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/mindquantum/zh_cn/mindspore_quantum_simulator.py)&emsp;\n",
        "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.png)](https://gitee.com/mindspore/docs/blob/master/docs/mindquantum/docs/source_zh_cn/quantum_simulator.ipynb)\n",
        "\n",
        "## Summary\n",
        "\n",
        "After building the quantum circuit, we need to specify a back end to run the quantum circuit. In MindQuantum, we can use the quantum Simulator 'Simulator' to simulate the quantum circuit. In this tutorial we declare a two-bit 'ProjectQ' simulator to introduce the key features of the simulator.\n",
        "\n",
        "## Environment preparation\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import the modules that this tutorial depends on."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np                             # Import the numpy library and abbreviate to np\n",
        "from mindquantum.simulator import Simulator  # Import the Simulator class from mindquantum. simulator\n",
        "from mindquantum.core import X, H, RY  # Import quantum gate H, X, RY"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Description:\n",
        "\n",
        "(1) Numpy is a powerful Python library used to perform calculations on multidimensional arrays. It supports a large number of dimensional arrays and matrix operations. It also provides a large number of mathematical function libraries for array operations.\n",
        "\n",
        "(2) MindQuantum is a quantum-classical hybrid computing framework that supports training and reasoning of various quantum neural networks;\n",
        "\n",
        "(3) The quantum gate to be executed in the quantum circuit set up needs to be imported from mindquantum. core module;"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "projectq simulator with 2 qubits (little endian).\n",
              "Current quantum state:\n",
              "1¦00⟩"
            ]
          },
          "execution_count": 2,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sim = Simulator('projectq', 2)  #Declare a two-bit ProjectQ simulator\n",
        "sim  #Display simulator status"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In MindQuantum, we can import the simulator in the 'mindQuantum. simulator' module. The 'Simulator' class takes three arguments:\n",
        "\n",
        "- 'backend' : name of the simulator used. Currently, 'MindQuantum' supports' ProjectQ 'as a backend for emulation.\n",
        "- 'n_qubits' : The number of bits used by the simulator, which is 2 here.\n",
        "- 'seed' : the random seed used by the simulator when running the randomness correlation algorithm. By default, the seed is a random number, which is not required.\n",
        "\n",
        "From the output of the simulator, we can see that this is a 2-bit simulator of 'ProjectQ' and little Endian. Little Endian means that throughout the simulator, we put bits with small bits to the right of the quantum state vector. Next, the output also states what quantum state the simulator is currently in, and after the simulator is initialized, the current quantum state defaults to zero. Note that the quantum simulator always maintains an internal quantum state that changes when we apply a quantum gate or a quantum circuit to the simulator, but does not change when we simply want to obtain some information about the quantum state. There are two types of operations for the quantum simulator:\n",
        "\n",
        "- Operations that change the quantum state, usually beginning with 'apply', mainly include the following\n",
        "- 'apply_gate' : applies a quantum gate to the simulator\n",
        "- 'apply_circuit' : applies a quantum circuit to the simulator\n",
        "- 'apply_hamiltonian' : Apply a Hamiltonian to the simulator. Note that the quantum state of the simulator is no longer a true quantum state\n",
        "- 'set_qs' : Sets the current quantum state of the simulator directly\n",
        "- ` reset ` : reset the state of the simulator to | 0 ⟩ state\n",
        "- Operations that do not change the quantum state, usually beginning with 'get', mainly include the following\n",
        "- 'get_QS' : gets the current quantum state of the simulator\n",
        "- 'get_expectation' : calculates the expected value of the simulator's current quantum state regarding an observed quantity\n",
        "- 'get_expectation_with_grad' : similar to the previous interface, except that this method also calculates the expected value gradient with respect to parameterized quantum lines\n",
        "- 'sampling' : in the current quantum state, sampling of the given quantum circuit\n",
        "\n",
        "Let's learn the basic operation of the simulator briefly.\n",
        "\n",
        "## Interacts with quantum gates and quantum circuits"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "projectq simulator with 2 qubits (little endian).\n",
              "Current quantum state:\n",
              "√2/2¦00⟩\n",
              "√2/2¦01⟩"
            ]
          },
          "execution_count": 3,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sim = Simulator('projectq', 2)  #Declare a 2-bit ProjectQ emulator\n",
        "sim.apply_gate(H.on(0))           #Apply a Hadamard gate to qubit 0\n",
        "sim  #Output quantum simulator information"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Above, we acted a Hadamard gate on the initial state of the quantum simulator and output the quantum state after evolution. Next we generate a parameterized quantum circuit and apply it to the current quantum state."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"156.8\" height=\"140\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"156.8\" height=\"140\" fill=\"#ffffff\" />\n<text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq0:\n </text>\n<text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq1:\n </text>\n<line x1=\"48.8\" x2=\"136.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"136.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n\n<rect x=\"72.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n\n<rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nRY\n </text>\n<text x=\"92.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\na\n </text>\n\n</svg></div>",
            "text/plain": [
              "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f913ab81460>"
            ]
          },
          "execution_count": 4,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "from mindquantum.core import Circuit   # Import Circuit module to build quantum Circuit\n",
        "\n",
        "circ = Circuit()                       #Declare an empty quantum circuit\n",
        "circ += H.on(1)                        #Add a Hadamard gate to it and apply it to qubit 1\n",
        "circ += RY('a').on(0)  #Add a parameterized RY gate to it and apply it to qubit 0\n",
        "circ.svg()  #Draws a quantum circuit picture in SVG format"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": [
              "projectq simulator with 2 qubits (little endian).\n",
              "Current quantum state:\n",
              "0.11851349145283657¦00⟩\n",
              "0.6971044056263442¦01⟩\n",
              "0.11851349145283657¦10⟩\n",
              "0.6971044056263442¦11⟩"
            ]
          },
          "execution_count": 5,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sim.apply_circuit(\n",
        "    circ, pr={'a': 1.234}\n",
        ")  #Apply a quantum circuit. When the circuit is a parameterized quantum circuit, we also need to provide parameter values.\n",
        "sim"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In the above code, we create a parameterized quantum circuit 'circ', which we then apply to the quantum simulator and set parameter 'A' to '1.234' by passing in a dictionary. Finally, the quantum state evolved from the quantum simulator is output."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Set and get the simulator state\n",
        "\n",
        "We use 'get_qs(ket=False)' to check the state of the current simulator,\n",
        "The ket argument is a bool that determines whether the state of the current simulator is returned as a ket, numpy.ndarray when ket=False, or ket when ket=True. The default ket = False."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "[0.11851349+0.j 0.69710441+0.j 0.11851349+0.j 0.69710441+0.j]\n"
          ]
        }
      ],
      "source": [
        "print(sim.get_qs()\n",
        "      )  #View the simulator status and return the result in numpy.ndarray form"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "0.11851349145283657¦00⟩\n",
            "0.6971044056263442¦01⟩\n",
            "0.11851349145283657¦10⟩\n",
            "0.6971044056263442¦11⟩\n"
          ]
        }
      ],
      "source": [
        "print(sim.get_qs(\n",
        "    True))  #View the simulator status and return the result in ket form"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "During actual code writing, we often need to specify an initial state for the simulator to start evolving, which can be done using 'set_qs()'.\n",
        "\n",
        "For example, we want the emulator state to be\n",
        "\n",
        "$$\n",
        "\\frac{\\sqrt{3}}{3}|00⟩+\\frac{\\sqrt{6}}{3}|11⟩\n",
        "$$\n",
        "\n",
        "Step 1: We calculate the vector form of the target state:\n",
        "\n",
        "$$\n",
        "\\frac{\\sqrt{3}}{3}|00⟩+\\frac{\\sqrt{6}}{3}|11⟩ =\\frac{\\sqrt{3}}{3}\\times\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "1\\\\\n",
        "0\n",
        "\\end{array}\n",
        "\\right)\n",
        "\\otimes\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "1\\\\\n",
        "0\n",
        "\\end{array}\n",
        "\\right)+\n",
        "\\frac{\\sqrt{6}}{3}\\times\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "0\\\\\n",
        "1\n",
        "\\end{array}\n",
        "\\right)\\otimes\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "0\\\\\n",
        "1\n",
        "\\end{array}\n",
        "\\right)= \\frac{\\sqrt{3}}{3}\\times\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "1\\\\\n",
        "0\\\\\n",
        "0\\\\\n",
        "0\n",
        "\\end{array}\n",
        "\\right)+\n",
        "\\frac{\\sqrt{6}}{3}\\times\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "0\\\\\n",
        "0\\\\\n",
        "0\\\\\n",
        "1\n",
        "\\end{array}\n",
        "\\right)=\n",
        "\\left(\n",
        "\\begin{array}{l}\n",
        "\\frac{\\sqrt{3}}{3}\\\\\n",
        "0\\\\\n",
        "0\\\\\n",
        "\\frac{\\sqrt{6}}{3}\n",
        "\\end{array}\n",
        "\\right)\n",
        "$$\n",
        "\n",
        "Step 2: We assign this vector to the simulator using 'set_qs()' as its state:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "0.5773502691896258¦00⟩\n",
            "0.816496580927726¦11⟩\n"
          ]
        }
      ],
      "source": [
        "sim.set_qs(np.array([3**0.5, 0, 0,\n",
        "                     6**0.5]))  #Set simulator state without normalization\n",
        "print(sim.get_qs(True))                             #View simulator Status"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Viewing the simulator status through `get_qs()` can find that the current simulator status is we want to set the $\\frac{\\sqrt{3}}{3}|00⟩+\\frac{\\sqrt{6}}{3}|11⟩$.\n",
        "\n",
        "In the actual programming process, we often need to simulate the circuit for several times, which will lead to a very large memory consumption by opening the simulator more than once. We can reuse the simulator by resetting the existing simulator, thus reducing the memory consumption.\n",
        "\n",
        "We use 'reset()' to reset the simulator:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "[1.+0.j 0.+0.j 0.+0.j 0.+0.j]\n"
          ]
        }
      ],
      "source": [
        "sim.reset()          #Reset simulator\n",
        "print(sim.get_qs())  #View simulator Status"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "It can be found that the current simulator is reset to the initial $1|00⟩$ state, which is equivalent to a brand new simulator.\n",
        "\n",
        "Therefore, we can set up a corresponding quantum simulator and run a custom quantum circuit according to the quantum initial state we need. Get your hands on your first quantum circuit!\n",
        "\n",
        "## Quantum circuit sampling\n",
        "\n",
        "Circuit sampling refers to performing multiple simulation measurements on quantum circuits, and statistically measuring the frequency of occurrence of various results. **Sampling does not change the state in the quantum circuit**.\n",
        "\n",
        "`sampling(circuit, pr=None, shots=1, seed=None)`is the sampling method provided in `MindQuantum`, which accepts four parameters:\n",
        "\n",
        "- `circuit (Circuit)`：Quantum circuit for which sampling is desired, note that at least one measurement operation (i.e. sampling point) must be included in the circuit.\n",
        "- `pr (Union[None, dict, ParameterResolver])`：parameter resolver，When `circuit` is a parameterized circuit, the value of the parameter needs to be given.\n",
        "- `shots (int)`：The number of times to sample, default 1.\n",
        "- `seed`：The random seed for sampling, which is a random number by default and can be omitted."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"276.8\" height=\"140\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"276.8\" height=\"140\" fill=\"#ffffff\" />\n<text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq0:\n </text>\n<text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq1:\n </text>\n<line x1=\"48.8\" x2=\"256.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"256.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n\n<rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<circle cx=\"152.8\" cy=\"40.0\" r=\"4\" fill=\"#16acff\" />\n<line x1=\"152.8\" x2=\"152.8\" y1=\"40.0\" y2=\"100.0\" stroke=\"#16acff\" stroke-width=\"3\" />\n<rect x=\"132.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" />\n<line x1=\"138.8\" x2=\"166.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#ffffff\" stroke-width=\"4\" />\n<line x1=\"152.8\" x2=\"152.8\" y1=\"86.0\" y2=\"114.0\" stroke=\"#ffffff\" stroke-width=\"4\" />\n<rect x=\"192.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"212.8\" cy=\"50.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 200.0 50.4 A 12.8 12.8 0 0 1 225.60000000000002 50.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 216.90184831748593 33.93539030917347 L 225.21569219381655 29.135390309173467 L 225.21569219381655 38.73539030917347 L 221.8901546432843 36.815390309173466 L 214.04707658144957 50.4 L 212.38430780618347 49.44 L 220.2273858680182 35.85539030917347 Z\" fill=\"#ffffff\" />\n<rect x=\"192.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"212.8\" cy=\"110.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 200.0 110.4 A 12.8 12.8 0 0 1 225.60000000000002 110.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 216.90184831748593 93.93539030917347 L 225.21569219381655 89.13539030917347 L 225.21569219381655 98.73539030917347 L 221.8901546432843 96.81539030917347 L 214.04707658144957 110.4 L 212.38430780618347 109.44 L 220.2273858680182 95.85539030917347 Z\" fill=\"#ffffff\" />\n</svg></div>",
            "text/plain": [
              "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f913ab81700>"
            ]
          },
          "execution_count": 10,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "# Non-parameterized circuit sampling:\n",
        "from mindquantum import Measure  # Introduce measurement gate\n",
        "\n",
        "circ = Circuit()                 # Initialize the quantum circuit\n",
        "circ += H.on(0)  # The H gate acts on qubit 0\n",
        "circ += X.on(\n",
        "    1,\n",
        "    0)  # The X gate acts on qubit 1 and is controlled by qubit 0\n",
        "circ += Measure('q0').on(\n",
        "    0)  # Apply a measurement on qubit 0 and name this measurement 'q0'\n",
        "circ += Measure('q1').on(\n",
        "    1)  # Apply a measurement to qubit 1 and name this measurement 'q1'\n",
        "circ.svg()  # Draw a quantum circuit picture in SVG format"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space: pre;\"><span style=\"color: #808000; text-decoration-color: #808000\">shots: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1000</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000\">Keys: q1 q0│</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.00</span><span style=\"color: #808000; text-decoration-color: #808000\">   </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.128</span><span style=\"color: #808000; text-decoration-color: #808000\">       </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.256</span><span style=\"color: #808000; text-decoration-color: #808000\">       </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.384</span><span style=\"color: #808000; text-decoration-color: #808000\">       </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.512</span><span style=\"color: #808000; text-decoration-color: #808000\">        </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.64</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000\">───────────┼───────────┴───────────┴───────────┴───────────┴───────────┴</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000\">         </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">00</span><span style=\"color: #808000; text-decoration-color: #808000\">│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000\">           │</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000\">         </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">11</span><span style=\"color: #808000; text-decoration-color: #808000\">│▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000\">           │</span>\n",
              "<span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'00'</span><span style=\"color: #808000; text-decoration-color: #808000\">: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">488</span><span style=\"color: #808000; text-decoration-color: #808000\">, </span><span style=\"color: #008000; text-decoration-color: #008000\">'11'</span><span style=\"color: #808000; text-decoration-color: #808000\">: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">512</span><span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">}</span>\n",
              "</pre>\n"
            ],
            "text/plain": [
              "shots: 1000\n",
              "Keys: q1 q0│0.00   0.128       0.256       0.384       0.512        0.64\n",
              "───────────┼───────────┴───────────┴───────────┴───────────┴───────────┴\n",
              "         00│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒\n",
              "           │\n",
              "         11│▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓\n",
              "           │\n",
              "{'00': 488, '11': 512}"
            ]
          },
          "execution_count": 11,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sim.reset()\n",
        "result = sim.sampling(circ, shots=1000)  # Sample the circuit defined above 1000 times\n",
        "result"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "MindQuantum also provides the function of drawing SVG diagrams from sampling results:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"408.4\" height=\"147.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"408.4\" height=\"147.0\" fill=\"#ffffff\" />\n<text x=\"10\" y=\"17.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >\nShots:\n 1000\n </text>\n<text x=\"10\" y=\"31.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >\nKeys: q0 q1\n </text>\n<line x1=\"38.4\" x2=\"398.4\" y1=\"62.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"38.4\" x2=\"38.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"40.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.0\n </text>\n<line x1=\"38.4\" x2=\"38.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"98.4\" x2=\"98.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"100.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.102\n </text>\n<line x1=\"98.4\" x2=\"98.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"158.4\" x2=\"158.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"160.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.205\n </text>\n<line x1=\"158.4\" x2=\"158.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"218.4\" x2=\"218.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"220.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.307\n </text>\n<line x1=\"218.4\" x2=\"218.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"278.4\" x2=\"278.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"280.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.41\n </text>\n<line x1=\"278.4\" x2=\"278.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"338.4\" x2=\"338.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"340.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.512\n </text>\n<line x1=\"338.4\" x2=\"338.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<text x=\"29.4\" y=\"85.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n00\n </text>\n<line x1=\"31.4\" x2=\"38.4\" y1=\"85.0\" y2=\"85.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"38.4\" y=\"73.0\" width=\"285.9375\" height=\"24\" id=\"bar_0_1649988007528709375\" fill=\"#5e7ce0\" />\n<text x=\"334.3375\" y=\"85.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_0_1649988007528727097\" fill-opacity=\"0\" >\n488\n </text>\n<text x=\"29.4\" y=\"115.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n11\n </text>\n<line x1=\"31.4\" x2=\"38.4\" y1=\"115.0\" y2=\"115.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"38.4\" y=\"103.0\" width=\"300.0\" height=\"24\" id=\"bar_1_1649988007528766713\" fill=\"#16acff\" />\n<text x=\"348.4\" y=\"115.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_1_1649988007528788991\" fill-opacity=\"0\" >\n512\n </text>\n<animate xlink:href=\"#bar_0_1649988007528709375\" attributeName=\"width\" from=\"0\" to=\"285.9375\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 285.9375\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_1_1649988007528766713\" attributeName=\"width\" from=\"0\" to=\"300.0\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 300.0\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_1_1649988007528766713\" attributeName=\"fill\" from=\"#16acff\" to=\"#fac209\" dur=\"0.15s\" calcMode=\"spline\" values=\"#16acff; #fac209\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_0_1649988007528727097\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_1_1649988007528788991\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<text x=\"206.7\" y=\"41.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"middle\" >\nprobability\n </text>\n</svg></div>",
            "text/plain": [
              "<mindquantum.io.display.measure_res_svg_drawer.SVGMeasure at 0x7f9133353e50>"
            ]
          },
          "execution_count": 12,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "result.svg()  # Print out measurement results in SVG format"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We can see that in sampling 1000 times, '00' appears 499 times and '11' appears 501 times. The circuit we built actually produces a Bell state $\\frac{\\sqrt{2}}{2}|00⟩+\\frac{\\sqrt{2}}{2}|11⟩$. Intuitively, we can see that the probability of measuring the state to get '00' is $\\frac{1}{2}$, the probability of getting '11' is $\\frac{1}{2}$, the sampling result consistent with probability, slight errors are caused by simulator noise."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"376.8\" height=\"140\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"376.8\" height=\"140\" fill=\"#ffffff\" />\n<text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq0:\n </text>\n<text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >\nq1:\n </text>\n<line x1=\"48.8\" x2=\"356.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"48.8\" x2=\"356.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n\n<rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" />\n<text x=\"92.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nH\n </text>\n\n<circle cx=\"152.8\" cy=\"40.0\" r=\"4\" fill=\"#16acff\" />\n<line x1=\"152.8\" x2=\"152.8\" y1=\"40.0\" y2=\"100.0\" stroke=\"#16acff\" stroke-width=\"3\" />\n<rect x=\"132.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" />\n<line x1=\"138.8\" x2=\"166.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#ffffff\" stroke-width=\"4\" />\n<line x1=\"152.8\" x2=\"152.8\" y1=\"86.0\" y2=\"114.0\" stroke=\"#ffffff\" stroke-width=\"4\" />\n\n<rect x=\"192.8\" y=\"80.0\" width=\"80.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" />\n<text x=\"232.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\nRY\n </text>\n<text x=\"232.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >\ntheta\n </text>\n\n<rect x=\"192.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"212.8\" cy=\"50.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 200.0 50.4 A 12.8 12.8 0 0 1 225.60000000000002 50.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 216.90184831748593 33.93539030917347 L 225.21569219381655 29.135390309173467 L 225.21569219381655 38.73539030917347 L 221.8901546432843 36.815390309173466 L 214.04707658144957 50.4 L 212.38430780618347 49.44 L 220.2273858680182 35.85539030917347 Z\" fill=\"#ffffff\" />\n<rect x=\"292.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#ff7272\" fill-opacity=\"1\" />\n<circle cx=\"312.8\" cy=\"110.4\" r=\"1.6\" fill=\"#ffffff\" />\n<path d=\"M 300.0 110.4 A 12.8 12.8 0 0 1 325.6 110.4\" stroke=\"#ffffff\" stroke-width=\"2.4000000000000004\" fill-opacity=\"0\" />\n<path d=\"M 316.9018483174859 93.93539030917347 L 325.21569219381655 89.13539030917347 L 325.21569219381655 98.73539030917347 L 321.8901546432843 96.81539030917347 L 314.0470765814496 110.4 L 312.3843078061835 109.44 L 320.2273858680182 95.85539030917347 Z\" fill=\"#ffffff\" />\n</svg></div>",
            "text/plain": [
              "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f9133304520>"
            ]
          },
          "execution_count": 13,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "# Parameterized circuit sampling:\n",
        "para_circ = Circuit()  # Initialize the quantum circuit\n",
        "para_circ += H.on(0)  # The H gate acts on qubit 0\n",
        "para_circ += X.on(1,\n",
        "                  0)  # The X gate acts on qubit 1 and is controlled by qubit 0\n",
        "para_circ += RY('theta').on(1)  # The RY(theta) gate acts on the qubit 1\n",
        "para_circ += Measure('0').on(\n",
        "    0)  # Apply a measurement on qubit 0 and name this measurement 'q0'\n",
        "para_circ += Measure('q1').on(\n",
        "    1)  # Apply a measurement to qubit 1 and name this measurement 'q1'\n",
        "para_circ.svg()  # Draw a quantum circuit picture in SVG format"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "image/svg+xml": "<div class=\"nb-html-output output_area\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"408.4\" height=\"147.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<rect x=\"0\" y=\"0\" width=\"408.4\" height=\"147.0\" fill=\"#ffffff\" />\n<text x=\"10\" y=\"17.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >\nShots:\n 1000\n </text>\n<text x=\"10\" y=\"31.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >\nKeys: 0 q1\n </text>\n<line x1=\"38.4\" x2=\"398.4\" y1=\"62.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"38.4\" x2=\"38.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"40.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.0\n </text>\n<line x1=\"38.4\" x2=\"38.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<line x1=\"98.4\" x2=\"98.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"100.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.103\n </text>\n<line x1=\"98.4\" x2=\"98.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"158.4\" x2=\"158.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"160.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.205\n </text>\n<line x1=\"158.4\" x2=\"158.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"218.4\" x2=\"218.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"220.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.308\n </text>\n<line x1=\"218.4\" x2=\"218.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"278.4\" x2=\"278.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"280.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.41\n </text>\n<line x1=\"278.4\" x2=\"278.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<line x1=\"338.4\" x2=\"338.4\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<text x=\"340.4\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >\n0.513\n </text>\n<line x1=\"338.4\" x2=\"338.4\" y1=\"62.0\" y2=\"137.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" />\n<text x=\"29.4\" y=\"85.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n00\n </text>\n<line x1=\"31.4\" x2=\"38.4\" y1=\"85.0\" y2=\"85.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"38.4\" y=\"73.0\" width=\"300.0\" height=\"24\" id=\"bar_0_1649988007818207529\" fill=\"#5e7ce0\" />\n<text x=\"348.4\" y=\"85.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_0_1649988007818237401\" fill-opacity=\"0\" >\n513\n </text>\n<text x=\"29.4\" y=\"115.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >\n11\n </text>\n<line x1=\"31.4\" x2=\"38.4\" y1=\"115.0\" y2=\"115.0\" stroke=\"#adb0b8\" stroke-width=\"1\" />\n<rect x=\"38.4\" y=\"103.0\" width=\"284.7953216374269\" height=\"24\" id=\"bar_1_1649988007818265369\" fill=\"#16acff\" />\n<text x=\"333.1953216374269\" y=\"115.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_1_1649988007818278671\" fill-opacity=\"0\" >\n487\n </text>\n<animate xlink:href=\"#bar_0_1649988007818207529\" attributeName=\"width\" from=\"0\" to=\"300.0\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 300.0\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_1_1649988007818265369\" attributeName=\"width\" from=\"0\" to=\"284.7953216374269\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 284.7953216374269\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" />\n<animate xlink:href=\"#bar_0_1649988007818207529\" attributeName=\"fill\" from=\"#5e7ce0\" to=\"#fac209\" dur=\"0.15s\" calcMode=\"spline\" values=\"#5e7ce0; #fac209\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_0_1649988007818237401\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<animate xlink:href=\"#bar_text_1_1649988007818278671\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" />\n<text x=\"206.7\" y=\"41.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"middle\" >\nprobability\n </text>\n</svg></div>",
            "text/plain": [
              "<mindquantum.io.display.measure_res_svg_drawer.SVGMeasure at 0x7f91333047f0>"
            ]
          },
          "execution_count": 14,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sim.reset()\n",
        "result = sim.sampling(para_circ, {'theta': 0},\n",
        "                      shots=1000)  # Assign the circuit parameter 'theta' defined above to 0 and sample 1000 times\n",
        "result.svg()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We can see that '00' appears 495 times and '11' appears 505 times in the sampling result. In fact, the RY gate parameter is assigned to 0, which is the I gate and equivalent to not doing any operation on the circuit. Therefore, the sampling circuit is essentially the same as the above Non-parameterized circuit. It can be observed that the results of two times sampling are almost the same, as expected.\n",
        "\n",
        "If you want to learn more about how to measure quantum circuits and understand the theoretical explanation of the distribution of sampling results, please click: [Quantum Measurement Tutorial](https://gitee.com/buyulin/mindquantum/blob/master/tutorials/quantum_measurement.ipynb ).\n",
        "\n",
        "For more information about MindQuantum API, please click: [https://mindspore.cn/mindquantum/](https://mindspore.cn/mindquantum/)."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}
